﻿@model EvincePayroll.Data.EmployeeLeaveRequestData 
@{
    
}
<script src="../../Scripts/Data_Table/jquery.dataTables.min.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function () {
        setupDialogBox('formAddNewRow', 'btnAddNewRow');
        setDatePicker('date-picker-from');
        setDatePicker('date-picker-to');
        var oTable2 = $('#leaveRequestsTable').dataTable({
            "bServerSide": true,
            "sAjaxSource": "/LeaveRequests/AjaxGetLeaveRequestsAdmin",
            "bProcessing": true,
            "sPaginationType": "full_numbers",
            "aoColumns":
[
{ "sName": "LeaveId", "sTitle": "Leave ID", "bVisible": false, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[0]; } },
{ "sName": "EmployeeId", "sTitle": "Employee ID", "sWidth": 80, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[1]; } },
{ "sName": "EmployeeName", "sTitle": "Employee Name", "sWidth": 120, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[2]; } },
{ "sName": "LeaveReason", "sTitle": "Leave Reason", "sWidth": 250, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[3]; } },
{ "sName": "Status", "sTitle": "Status", "sWidth": 70, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[4]; } },
{ "sName": "Type", "sTitle": "Type", "sWidth": 70, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[5]; } },
{ "sName": "From", "sTitle": "From", "sWidth": 80, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[6]; } },
{ "sName": "To", "sTitle": "To", "sWidth": 80, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[7]; } },
{ "sName": "ReportManager", "sTitle": "Reporting Manager", "sWidth": 70, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[8]; } },
{ "sName": "Action", "sTitle": "Action", "sWidth": 80, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[9]; } },
{ "sName": "Action", "sTitle": "Withdraw", "sWidth": 80, "bVisible": true, "bSortable": true, "fnRender": function (oObj) { return oObj.aData[10]; } },

]
        });
        oTable2 = $('#leaveRequestsTable').dataTable();

        $('#btnClose').click(function () {
            $('#popupWindow').hide();
        });

        $('#formAddNewRow').hide();

        // $('#btnAddNewRow').click(function () {
        //   $('#formAddNewRow').show();

        //      });
        $('#btnCancel').click(function () {
            $('#formAddNewRow').dialog("close");
            return false;
        });



        var leaveType = $('#leaveType').val();
        if (leaveType == 0) {
            $("#leaveTypeFrom").hide();
            $("#leaveTypeTo").hide();
        }
        $('#leaveType').change(function () {
            var leaveType = $('#leaveType').val();
            if (leaveType == 0) {
                $("#leaveTypeFrom").hide();
                $("#leaveTypeTo").hide();
            }
            if (leaveType == 'Half Day') {
                $("#leaveTypeFrom").show();
                $("#leaveTypeTo").hide();
            }
            if (leaveType == 'Full Day') {
                $("#leaveTypeFrom").show();
                $("#leaveTypeTo").show();
            }
        });





        $('#reasonerror').hide();
        $('#fromDate').hide();
        $("#leaveTypeError").hide();
        $('#todate').hide();
        $('#reportToError').hide();
        $('#btnCancel').click(function () {
            $('#txtLeaveReason').val('');
            $('#date-picker-to').val('');
            $('#date-picker-from').val('');
            return false;
        });

        $("#formAddNewRow").submit(function () {
            var errorFlag = false;
            $('.requireded').each(function () {
                if ($(this).val() == '') {
                    if ($(this).prev().attr('class') != 'error') {
                        $(this).before('<span class="error"></span>');
                    }
                    $(this).css({
                        border: '1px solid red'
                    });
                    errorFlag = true;
                } else {
                    if ($(this).prev().attr('class') == 'error') {
                        $(this).prev().remove();
                        $(this).removeAttr('style');
                    }
                }
            });
            if (errorFlag == true) {
                return false;
            }
            else {
                $.ajax({
                    type: "POST",
                    url: "/LeaveRequests/AddData",
                    data: $(this).serialize(),
                    dataType: 'json',
                    success: function (result) {
                        var oTable2 = $('#leaveRequestsTable').dataTable();
                        oTable2.fnDraw();
                        $('#formAddNewRow').dialog("close");
                       // clereTextBoxes();
                        
                    }
                });
                
            }

            return false;


        });


    });
    function WithdrawLeave(leaveId,flag) {

        $.ajax({
            type: 'post',
            url: '/LeaveRequests/LeaveWithdraw?leaveRequestId=' + leaveId+'&flag='+flag,
            success: function (data) {
                oTable2 = $('#leaveRequestsTable').dataTable();
                oTable2.fnDraw();
            }
        });
    }
    function updateStatusAccept(e, numberOfDays, fromDate, id) {
        $('#popupWindow').show();
        $('#btnSubmit').click(function () {
            var status = 'Approved';
            var message = $('#remarkMessage').val();
            $.ajax({
                type: "POST",
                url: "/LeaveRequests/UpdateLeaveRequestStatus?leaveRequestId=" + id + "&status=" + status + " &message=" + message + "&numberOfDays=" + numberOfDays + "&fromDate=" + fromDate,
                success: function () {
                    var oTable2 = $('#leaveRequestsTable').dataTable();
                    oTable2.fnDraw();
                    $('#popupWindow').hide();
                    $('#remarkMessage').val('');
                }
            });
        });
    }
    function updateStatusReject(e, numberOfDays, fromDate, id, flag) {
        $('#popupWindow').show();
        $('#btnSubmit').click(function () {
            var status = 'Not Approved';
            var message = $('#remarkMessage').val();
            $.ajax({
                type: "POST",
                url: "/LeaveRequests/UpdateLeaveRequestStatus?leaveRequestId=" + id + "&status=" + status + " &message=" + message + "&numberOfDays=" + numberOfDays + "&fromDate=" + fromDate + "&flag=" + flag,
                //url: "/LeaveRequests/UpdateLeaveRequestStatus?leaveRequestId=" + id + "&status=Not Approved &message=" + message,
                success: function () {
                    var oTable2 = $('#leaveRequestsTable').dataTable();
                    oTable2.fnDraw();
                    $('#popupWindow').hide();
                    $('#remarkMessage').val('');
                }
            });
        });
    }
    </script>




<div class="grid_10" >
            <div class="box round first grid">
            <div id="demo">
                <h2>Leave Requests</h2>
                <div class="block">
                      <button id="btnAddNewRow" class="btn btn-orange" value="Ok">Add Leave Record</button> &nbsp;&nbsp;&nbsp;
                    <table class="data display datatable" id="leaveRequestsTable">
					<thead>
                <tr>
                 
                     <th>
                    </th>
                    <th>
                    </th>
                    <th>
                    </th> 
                    <th>
                    </th>                    
                    <th>
                        
                    </th>
                     <th>
                        
                    </th>
                    <th>
                        
                    </th>
                    <th>
                        
                    </th>
                    <th>
                        
                    </th>
                    <th>
                        
                    </th>
                    <th>
                        
                    </th>
                </tr>
            </thead>
					
				</table>
            
                <form id="formAddNewRow" method="post" action="AddData" title="Add Leave Request">
    
    <table class="form">
    <tr><th colspan="2"></th>
                           
                         
                         </tr>
                         <tr>
                            <td class="left">
                                <label class ="center">
                                    EmployeeName</label>
                            </td>
                            <td class="right">
                            @Html.DropDownListFor(m => m.EmployeeId, new SelectList(ViewBag.Name as System.Collections.IEnumerable, "Id", "FirstName"), "", new { style = "width:80%", @class = "requireded" })
                             
                            </td>
                         
                         </tr>
                        <tr>
                            <td class="left">
                                <label class ="center">
                                    Leave Reason</label>
                            </td>
                            <td class="right">
                            @Html.TextBoxFor(m => m.LeaveReason, new { style = "width:80%", id = "txtLeaveReason", @class = "requireded" })
                                
                               <span class="error" id="reasonerror">*</span>
                            </td>
                            </tr>
                            <tr>
                            <td class="left">
                                <label class ="center">
                                    Leave Type</label>
                            </td>
                            <td>
                            <select id="leaveType" name="leaveType" class = "requireded" >
                            <option value="0">Select</option>
                            <option value="Half Day">Half Day</option>
                            <option value="Full Day">Full Day</option>
                            </select>
                                
                                <span class="error" id="leaveTypeError">*</span>
                            </td>
                            </tr>
                            <tr id="leaveTypeFrom">
                            <td class="left">
                                <label>
                                    FromDate</label>
                            </td>
                            <td class="right">
                                 @Html.TextBoxFor(m => m.FromDate, new { style = "width:80%", id = "date-picker-from", @readonly = "readonly", @name = "FromDate", @class = "requireded" })
                                 

                                <span class="error" id="fromDate">*</span>
                            </td>
                            </tr>
                            <tr id="leaveTypeTo">
                            <td class="left">
                                <label>
                                    ToDate</label>
                            </td>
                            <td class="right">
                                 @Html.TextBoxFor(m => m.ToDate, new { style = "width:80%", id = "date-picker-to", @readonly = "readonly", @name = "ToDate" })
                                 
                                <span class="error" id="todate">*</span>
                            </td>
                            </tr>
                         <tr>
                            <td class="left">
                                <label>
                                    ReportTo</label>
                            </td>
                            <td class="right">
                                @Html.DropDownListFor(m => m.ReportTo, new SelectList(ViewBag.ReportTo as System.Collections.IEnumerable, "Id", "ReportToManager"), "", new { style = "width:80%", id = "ReportTo", @class = "requireded" })
                                <span class="error" id="reportToError">*</span>
                            </td>
                           
                        </tr>
                        <tr>
                            <td class="left">
                                <label>
                                    AssignTo</label>
                            </td>
                            <td class="right">
                               @Html.DropDownListFor(m => m.AssignTo, new SelectList(ViewBag.AssignTo as System.Collections.IEnumerable, "Id", "AssignToEmployee"), "", new { style = "width:80%", id = "AssignTo", })
                               @* <span class="error">This is a required field.</span>*@
                            </td>
                           
                        </tr>
                        <tr>
                            <td align="center">
                                <label>
                                    Status</label>
                            </td>
                            <td>
                               @Html.DropDownListFor(m => m.Status, new SelectList(ViewBag.Status as System.Collections.IEnumerable, "ParamId", "ParamValue"), "", new { style = "width:80%", id = "Status", @class = "requireded" })
                               @* <span class="error">This is a required field.</span>*@
                            </td>
                           
                        </tr>
                        <tr>
                            <td align="center">
                               <button class="btn btn-orange" id="btnSubmitRequest">Submit</button>
                            </td>
                            <td>
                               <button class="btn btn-orange" id="btnCancel">Cancel</button>
                            </td>
                           
                        </tr>
                    </table>
</form>
                   <div class="grid_5" id="popupWindow" style="display:none;height: 80px;left: 500px;position: fixed;top: 190px;width: 400px;">
            <div class="box round">
                <h2>
                    Leave Accept/Reject Remark</h2>
                <div class="block">
                   <textarea id="remarkMessage" cols="45" rows="5"></textarea>
                    <div class="block">
                      <table width="80%">
                      <tr>
                      <td align="center">
                       <button class="btn btn-orange" id="btnSubmit">Submit</button>
                       </td>
                      <td align="center">
                       <button class="btn btn-orange" id="btnClose">Close</button>
                       </td>
                       </tr>
                       </table>
                       </div>
                </div>
            </div>
        </div>

                    
                </div>
                </div>
            </div>
            
        </div>
        

